using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;


using System.Data.Linq;
using System.Linq;

using DataLayer;

namespace BusinessLayer.Activities
{
   public partial class Update_UserSettings : System.Workflow.ComponentModel.Activity
   {
      public Update_UserSettings()
      {
         //InitializeComponent();
      }

      private static DependencyProperty UserIdProperty = DependencyProperty.Register("UserId", typeof(Guid), typeof(Update_UserSettings));
      public Guid UserId
      {
         get { return (Guid)base.GetValue(UserIdProperty); }
         set { base.SetValue(UserIdProperty, value); }
      }

      private static DependencyProperty TabIdProperty = DependencyProperty.Register("TabId", typeof(int), typeof(Update_UserSettings));
      public int TabId
      {
         get { return (int)base.GetValue(TabIdProperty); }
         set { base.SetValue(TabIdProperty, value); }
      }

      protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
      {
         if (TabId > 0)
         {
            using (var db = DatabaseHelper.GetDashboardData())
            {
               var dUserSetting = db.UserSettings.Single(p => p.UserId == UserId);
               dUserSetting.ActiveTab = TabId;
               db.SubmitChanges();
            }
         }
         return ActivityExecutionStatus.Closed;
      }
   }
}